<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <script src="./vue.js"></script>
    <script src="./vue-router.js"></script>
  </head>
  <body>
    <div id="app">
      <router-link to="/books"> books page </router-link>
      <router-link to="/news"> news page </router-link>
      <hr />
      <router-view></router-view>
    </div>

    <script>
      const Books = {
        template: `
        <div>
        <h1>my books page</h1>
        <button @click='goNews'>点击跳转news page</button>
    </div>`,
        methods: {
          goNews() {
            //path==>query
            // this.$router.push({path: "/news", query:{name:'zs', age:19}});

            // name==>params
            this.$router.push({
              name: "mynews",
              params: { name: "ww", age: "11", hobby: "rap" },
            });
          },
        },
      };

      const News = {
        template:
          "<h1>my news page-----{{$route.query.name}}------{{$route.query.age}} -----{{$route.params.name}} -----{{$route.params.age}} -----{{$route.params.hobby}}</h1>",
      };

      let myRouter = new VueRouter({
        routes: [
          { path: "/books", component: Books, name: "mybooks" },
          { path: "/news", component: News, name: "mynews" },
        ],
      });

      var vm = new Vue({
        el: "#app",
        data: {},
        router: myRouter,
      });
    </script>
  </body>
</html>
